package com.cdn.allmobilestore.ui;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebStorage;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.cdn.allmobilestore.R;
import com.cdn.allmobilestore.ulti.Constant;


public class PromotionFragment extends BaseFragment 
{
	
	
	public PromotionFragment() {
		super();
		// TODO Auto-generated constructor stub
	}

	/* (non-Javadoc)
	 * @see android.support.v4.app.Fragment#onActivityCreated(android.os.Bundle)
	 */
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onActivityCreated(savedInstanceState);
	}

	/* (non-Javadoc)
	 * @see android.support.v4.app.Fragment#onCreate(android.os.Bundle)
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		//
		
	}

	/* (non-Javadoc)
	 * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
	 */
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
	
		View view = inflater.inflate(R.layout.fragment_tutorial, container, false);
		WebView webview = (WebView)view.findViewById(R.id.webview);
		webview.setWebChromeClient(new WebChromeClient() {
			@Override
			public void onExceededDatabaseQuota(String url, String
			databaseIdentifier, long currentQuota, long estimatedSize,
			long totalUsedQuota, WebStorage.QuotaUpdater quotaUpdater) {
			quotaUpdater.updateQuota(estimatedSize * 2); // try to keep quota size as big as possible else database will not get created in HTML 5 app
			}
			});
			webview.setWebViewClient(new WebViewClient() {
		        @Override
		        public boolean shouldOverrideUrlLoading(WebView view, String url) {
		        	if(url.contains("download") || url.contains("getapk"))
		        	{
		        		return true;
		        	}
		        	else
		        	{
		        		view.loadUrl(url);
			            return false;
		        	}
		            
		        }
		    });
			WebSettings settings = webview.getSettings();
			settings.setJavaScriptEnabled(true);
			settings.setJavaScriptCanOpenWindowsAutomatically(true);
			settings.setDatabaseEnabled(true);

			String databasePath = this.getActivity().getApplicationContext().getDir("database", Context.MODE_PRIVATE).getPath();
			settings.setDatabasePath(databasePath);
		webview.loadUrl(Constant.ADVERTISE_URL);
		
		return view;
	}

	
	
	
}
